package com.zhhs.project.act.activity.controller;


import com.zhhs.common.utils.poi.ExcelUtil;
import com.zhhs.framework.aspectj.lang.annotation.Log;
import com.zhhs.framework.aspectj.lang.enums.BusinessType;
import com.zhhs.framework.web.controller.BaseController;
import com.zhhs.framework.web.domain.AjaxResult;
import com.zhhs.framework.web.page.TableDataInfo;
import com.zhhs.project.act.activity.domian.ActActivityAwardWay;
import com.zhhs.project.act.activity.service.IActActivityAwardWayService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 派奖方式Controller
 *
 * @author zhhs
 * @date 2022-11-09
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wecom/activity/way")
public class ActActivityAwardWayController extends BaseController
{


    @Autowired
    private IActActivityAwardWayService actActivityAwardWayService;
    /**
     * 查询派奖方式列表
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityawardway:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActActivityAwardWay actActivityAwardWay)
    {
        startPage();
        List<ActActivityAwardWay> list = actActivityAwardWayService.selectActActivityAwardWayList(actActivityAwardWay);
        return getDataTable(list);
    }

    /**
     * 导出派奖方式列表
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityawardway:export')" )
    @Log(title = "派奖方式" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(ActActivityAwardWay actActivityAwardWay)
    {
        List<ActActivityAwardWay> list = actActivityAwardWayService.selectActActivityAwardWayList(actActivityAwardWay);
        ExcelUtil<ActActivityAwardWay> util = new ExcelUtil<ActActivityAwardWay>(ActActivityAwardWay.class);
        return util.exportExcel(list, "派奖方式数据");
    }



    /**
     * 新增保存派奖方式
     */
    @PreAuthorize("@ss.hasPermi('activity:way:add')")
    @Log(title = "派奖方式", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActActivityAwardWay actActivityAwardWay)
    {
        return toAjax(actActivityAwardWayService.insertActActivityAwardWay(actActivityAwardWay));
    }

//    /**
//     * 修改派奖方式
//     */
//    @GetMapping("/edit/{activityId}")
//    public String edit(@PathVariable("activityId") Long activityId, ModelMap mmap)
//    {
//        ActActivityAwardWay actActivityAwardWay = new ActActivityAwardWay();
//        actActivityAwardWay.setActivityId(activityId);
//        List<ActActivityAwardWay> activityAwardWayList = actActivityAwardWayService.selectActActivityAwardWayList(actActivityAwardWay);
//        if (CollectionUtils.isNotEmpty(activityAwardWayList)){
//            mmap.put("actActivityAwardWay", activityAwardWayList.get(0));
//        }
//        return prefix + "/edit";
//    }

    /**
     * 修改派奖方式
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityawardway:edit')" )
    @Log(title = "派奖方式" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult editSave(ActActivityAwardWay actActivityAwardWay)
    {
        return toAjax(actActivityAwardWayService.updateActActivityAwardWay(actActivityAwardWay));
    }

    /**
     * 删除派奖方式
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityawardway:remove')" )
    @Log(title = "派奖方式" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids )
    {
        return toAjax(actActivityAwardWayService.deleteActActivityAwardWayByIds(String.valueOf(ids)));
    }

    /**
     * 获取派奖方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityawardway:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(actActivityAwardWayService.selectActActivityAwardWayByActivityId(id));
    }
}
